import * as Koa from "koa";
import { createContainer, Lifetime } from "awilix";
import { scopePerRequest, loadControllers } from "awilix-koa";
import * as render from "koa-swig";
import * as serve from "koa-static";
import { join } from "path";
import co from "co";
const app = new Koa();
app.context.render = co.wrap(
  render({
    root: join(__dirname, "views"),
    autoescape: true,
    writeBody: false,
    ext: "html"
  })
);
app.use(serve(__dirname + '/assets'));
const container = createContainer();
container.loadModules([__dirname + "/service/*.ts"], {
  formatName: "camelCase",
  resolverOptions: {
    lifetime: Lifetime.SCOPED
  }
});
app.use(scopePerRequest(container));
app.use(loadControllers(__dirname + "/routers/*.ts"));
app.listen(3000, () => {
  console.log("service🐻, BFF 服务启动成功");
});
